#include<bits/stdc++.h>
using namespace std;

int T,n,m,L,V;
int d[100010],v[100010],a[100010],p[100010];
float cl[100010][2];

float suan(int x){
	float zhi;
	zhi=V*V-v[x]*v[x];
	zhi/=2*a[x];
	return zhi;
}

bool panv(int x){
	for(int i=1;i<=m;i++){
		if(p[i]>=cl[x][0]&&p[i]<=cl[x][1]){
			return true;
		}
	}return false;
}

int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","W",stdout);
	scanf("%d",&T);
	while(T){
		T--;
		scanf("%d%d%d%d",&n,&m,&L,&V);
		for(int i=1;i<=n;i++){
			scanf("%d%d%d",&d[i],&v[i],&a[i]);
		}
		for(int i=1;i<=m;i++){
			scanf("%d",&p[i]);
		}
		for(int i=1;i<=n;i++){
			if(a[i]<0){
				if(v[i]<=V) cl[i][0]=1<<30,cl[i][1]=1<<30;
				else cl[i][0]=d[i],cl[i][1]=d[i]+suan(i);
			}
			else if(a[i]==0){
				if(v[i]<=V) cl[i][0]=1<<30,cl[i][1]=1<<30;
				else cl[i][0]=d[i],cl[i][1]=L;
			}
			else if(a[i]>0){
				if(v[i]>V) cl[i][0]=d[i],cl[i][1]=L;
				else if(v[i]==V) cl[i][0]=d[i]+1,cl[i][1]=L;
				else cl[i][0]=d[i]+suan(i),cl[i][1]=L;
			}
		}
		int cans=0;
		for(int i=1;i<=n;i++){
			if(panv(i)) cans++;
		}
		printf("%d\n",cans);
	}
	return 0;
}
